package com.ruoyi.project.dict.ebookcontent.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.ebookcontent.domain.EbookContent;
import com.ruoyi.project.dict.ebookcontent.service.IEbookContentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子资料内容Controller
 *
 * @author shixiangwen
 * @date 2021-12-29
 */
@Controller
@RequestMapping("/dict/ebookcontent")
public class EbookContentController extends BaseController {

    private String prefix = "dict/ebookcontent";

    @Autowired
    private IEbookContentService ebookContentService;

    @RequiresPermissions("dict:ebookcontent:view")
    @GetMapping("/{catalogId}")
    public String ebookcontent(@PathVariable("catalogId") Integer catalogId, ModelMap mmap) {
        mmap.put("catalogId", catalogId);
        return prefix + "/ebookcontent";
    }

    /**
     * 查询电子资料内容列表
     */
    @RequiresPermissions("dict:ebookcontent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EbookContent ebookContent) {
        startPage();
        List<EbookContent> list = ebookContentService.selectEbookContentList(ebookContent);
        return getDataTable(list);
    }

    /**
     * 导出电子资料内容列表
     */
    @RequiresPermissions("dict:ebookcontent:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EbookContent ebookContent) {
        List<EbookContent> list = ebookContentService.selectEbookContentList(ebookContent);
        ExcelUtil<EbookContent> util = new ExcelUtil<EbookContent>(EbookContent.class);
        return util.exportExcel(list, "ebookcontent");
    }

    /**
     * 新增电子资料内容
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存电子资料内容
     */
    @RequiresPermissions("dict:ebookcontent:add")
    @Log(title = "电子资料内容", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EbookContent ebookContent) {
        return toAjax(ebookContentService.insertEbookContent(ebookContent));
    }

    /**
     * 修改电子资料内容
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        EbookContent ebookContent = ebookContentService.selectEbookContentById(id);
        mmap.put("ebookContent", ebookContent);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子资料内容
     */
    @RequiresPermissions("dict:ebookcontent:edit")
    @Log(title = "电子资料内容", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EbookContent ebookContent) {
        return toAjax(ebookContentService.updateEbookContent(ebookContent));
    }

    /**
     * 删除电子资料内容
     */
    @RequiresPermissions("dict:ebookcontent:remove")
    @Log(title = "电子资料内容", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ebookContentService.deleteEbookContentByIds(ids));
    }
}
